package edu.zut.main.socket;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IpDemo {

    public static void main(String[] args) throws UnknownHostException {
        //根据百度的主机名获取ip对象
        InetAddress inetAddress = InetAddress.getByName("www.baidu.com");

        String hostName = inetAddress.getHostName();
        System.out.println("hostName = " + hostName);
        String hostAddress = inetAddress.getHostAddress();
        System.out.println("hostAddress = " + hostAddress);

        //获取本地主机ip对象
        InetAddress localHost = InetAddress.getLocalHost();
        String name = localHost.getHostName();
        System.out.println("name = " + name);
        String address = localHost.getHostAddress();
        System.out.println(address);


    }

}
